package com.guigu.servicegoods.controller;


import com.guigu.common_util.pojo.utils.Result;
import com.guigu.servicegoods.domain.TbCategoryBrand;
import com.guigu.servicegoods.service.TbCategoryBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-07-08
 */
@RestController
@RequestMapping("/servicegoods/categorybrand")
public class TbCategoryBrandController {

    @Autowired
    private TbCategoryBrandService categoryBrandService;

    // 分页条件查询
    @PostMapping("findPage")
    public Result findPage(@RequestBody(required = false) Map<String, Object> searchMap, Integer page, Integer size){
        return categoryBrandService.findPage(searchMap,page,size);
    }

    @PostMapping("/insert")
    public Result insert(@RequestBody TbCategoryBrand categoryBrand) {
        boolean save = categoryBrandService.save(categoryBrand);
        if (save){
            return Result.ok();
        }
        return Result.error();
    }

    @PostMapping("/update")
    public Result update(@RequestBody TbCategoryBrand categoryBrand) {
        boolean update = categoryBrandService.updateById(categoryBrand);
        if (update) {
            return Result.ok();
        }
        return Result.error();
    }

    @GetMapping("/delete")
    public Result delete(Integer id) {
        boolean remove = categoryBrandService.removeById(id);
        if (remove){
            return Result.ok();
        }
        return Result.error();
    }

//    @GetMapping("/findById")
//    public Result findById(Integer id) {
//        TbCategoryBrand categoryBrand = categoryBrandService.getById(id);
//        if (categoryBrand==null){
//            return Result.error();
//        }
//        return Result.ok().data("categoryBrand",categoryBrand);
//    }

}

